n = input()
if len(n) != 4 or not n.isdigit():
    print(0)
else:
    max_prime = 0 
    for i in range(1):
        for j in range(i + 1, 5):
            num = int(n[i:j])
            is_prime = True
            if num <= 1:
                is_prime = False
            else:
                for k in range(2, int(num**0.5) + 1):
                    if num % k == 0:
                        is_prime = False
                        break
            if is_prime and num > max_prime:
                max_prime = num
        print(max_prime)
